<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 5000px;
        }

        .box {
            width: 100%;
            height: 100px;
            background: pink;
        }

        .box1 {
            width: 100%;
            height: 100px;
            background: skyblue;
        }

        .search-wrap {
            width: 1200px;
            height: 75px;
            background: slateblue;
            margin: 0px auto;
            padding-top: 25px;
        }

        .search {
            width: 400px;
            height: 50px;
            border-radius: 25px;
            border: 3px solid green;
            margin: 0px auto;
            background: yellow;
            overflow: hidden;
        }

        .search>span {
            display: block;
            width: 50px;
            height: 50px;
            float: right;
            font-size: 12px;
            line-height: 50px;
            /* border-radius: 0px 25px 25px 0px; */
            background: skyblue;
            text-align: center;
        }

        .search-fixed {
            position: fixed;
            width: 100%;
            background: tomato;
            left: 0px;
            top: 0px;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <div class="box1"></div>
    <div class="search-wrap">
        <div class="search">
            <span>搜索</span>
        </div>
    </div>

    <script>
        var ss = document.getElementsByClassName('search-wrap')[0]
        var box1 = document.getElementsByClassName('box')[0]
        var box2 = document.getElementsByClassName('box1')[0]

        window.onscroll = function () {
            var top = window.scrollY
            if (top >= ss.clientHeight + box1.clientHeight + box2.clientHeight) {
                ss.className = 'search-wrap search-fixed'
            } else {
                ss.className = 'search-wrap'
            }
        }
    </script>
</body>

</html>